package com.cicc.beergamevirtualsimulationsystem.service.recordInit;

import cn.hutool.core.util.ObjUtil;
import com.cicc.beergamevirtualsimulationsystem.common.enums.userTypeEnum.RoleType;
import com.cicc.beergamevirtualsimulationsystem.entity.RecordDetailEntity;
import com.cicc.beergamevirtualsimulationsystem.entity.RecordEntity;
import com.cicc.beergamevirtualsimulationsystem.entity.RoleBindingEntity;
import org.springframework.stereotype.Component;

@Component
public class RecordInitRetailer extends BaseRecordInit{
    @Override
    public RecordDetailEntity initRecordDetailFirstPeriod(String downStreamId) {
        RecordDetailEntity recordDetailEntity = new RecordDetailEntity();
        setDemand(recordDetailEntity, orderNum);
        recordDetailEntity.setDownStreamRole(-1);
        return recordDetailEntity;
    }

    @Override
    public RecordDetailEntity initRecordDetailOtherPeriod(String downStreamId, String userId) {
        RecordDetailEntity recordDetailEntity = initRecordDetailFirstPeriod(downStreamId);
        recordDetailEntity.setAccumulateOweQuantity(recordDetailEntityMapOne.get(userId + downStreamId).getAccumulateOweQuantity() + recordDetailEntity.getOrderQuantity());
        return recordDetailEntity;
    }

    @Override
    public Integer getType() {
        return RoleType.RETAILER.getCode();
    }

    @Override
    public Integer setReceiverTotal(String userId) {
        return ObjUtil.isNotNull(recordDetailEntityMapN.get(userId)) ? recordDetailEntityMapN.get(userId).getDeliverQuantity() : 0;
    }

    @Override
    public Integer setAccumulateOweTotal(Integer orderTotal) {
        return orderTotal;
    }

    private void setDemand(RecordDetailEntity recordDetailEntity, Integer orderNum) {
        // TODO: 判断需求曲线类型值
        recordDetailEntity.setOrderQuantity(orderNum);
        recordDetailEntity.setOweQuantity(orderNum);
        recordDetailEntity.setAccumulateOweQuantity(orderNum);
    }
}
